#!/bin/bash

# Define the input and output directories
INPUT_DIR="/app/Input"
OUTPUT_DIR="/app/Output"
CONFIG_FILE="/app/chernc_configs.yml"

# Iterate over each sub-directory in /app/input
for D in "$INPUT_DIR"/*; do
    if [ -d "$D" ]; then
        # Extract the directory name
        DIR_NAME=$(basename "$D")
        
        # Create the corresponding sub-directory in /app/output
        OUTPUT_SUBDIR="$OUTPUT_DIR/$DIR_NAME"
        mkdir -p "$OUTPUT_SUBDIR"
        
        # Change to the output sub-directory
        cd "$OUTPUT_SUBDIR"
        export HF_ENDPOINT=https://hf-mirror.com
        # Run the command with the specified arguments
        COMMAND_TO_RUN="/app/cherncvenv/bin/chernc2rust --codeql /codeql/codeql"
        $COMMAND_TO_RUN -i "$INPUT_DIR/$DIR_NAME" -o "$OUTPUT_SUBDIR" -c "$CONFIG_FILE"
        
        
    fi
done